C (182/254)

From:Stephen Illingworth
Date:08 Apr 00 at 16:30:37
Subject:Re: StormC Exception

Hello Daithi

On 08-Apr-00, you wrote:

> Hello Daithi
>
> On 07-Apr-00, Daithi O'Cuinn wrote:
>> Hello,
>>
>> When trying to execute a small program using StormC's debugger, I get a
>> "program threw exception 10" requester on a fairly innocuous looking
>> section of code. What on earth is this?
>
> Just to follow up to myself, I may have been too quick to blame Storm. I
> compiled and executed the same code on vbcc, and I got a Line1010 emulator
> error. What is this some sort of invalid opcode? I am out of my depth
> here! I attach the code (it's very short and simple) in the hope that
> someone can tell me what the hell is happening. ;)
>
> It's a simple window open and event loop that waits for the close gadget
> to be pressed. I can see no obvious fault - perhaps someone wiser can
> help!
>

Hehehe! This was a stinker :-)

Remember a few weeks ago we had a thread discussing logical ANDs and ORs is
if statements? Well this bug highlights perfectly, the "problem".

Take a look at this line.

if (!(IntuitionBase = OpenLibrary("intuition.library", 39)) &&
(GfxBase = OpenLibrary("graphics.library", 39)) &&
(GadToolsBase = OpenLibrary("gadtools.library", 39))) return (1);

What happens here? Well, the first OpenLibrary() will most likely return a
valid pointer, however it is negated. Because this expression now
evaluates to "FALSE", the code will never run the two following
OpenLibraries(). Which leaves GFXBase and GadToolsBase uninitialized,
eventually causing the crash you witnessed.

Respect, Steve

------------------------------------------------------------------------
LOW RATE, NO WAIT!
Get a NextCard Visa, in 30 seconds! Get rates
as low as 2.9% Intro or 9.9% Fixed APR and no hidden fees.
Apply NOW!
http://click.egroups.com/1/2122/1/_/451227/_/955211602/
------------------------------------------------------------------------